package leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author:xufengxiang
 * @date 2023-03-16 19:23
 */
public class Code17 {

    public static List<String> letterCombinations(String digits) {
        int length = digits.length();
        if(length ==0){
            return new ArrayList<>();
        }
        String[] phoneNumbers=new String[]{"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};

        List<String> result = new ArrayList<>();
        for(int i=0;i<length;i++){
            char c = digits.charAt(i);
            String phoneNumber = phoneNumbers[c-'0'];
            if(phoneNumber.length()>0){
                List<String> add = new ArrayList<>();
                for(int j=0;j< phoneNumber.length();j++){
                    if(result.size() == 0){
                        StringBuilder sb = new StringBuilder();
                        sb.append(phoneNumber.charAt(j));
                        add.add(sb.toString());
                    }else{
                        for(int k=0;k<result.size();k++){
                            StringBuilder sb = new StringBuilder();
                            sb.append(result.get(k));
                            sb.append(phoneNumber.charAt(j));
                            add.add(sb.toString());
                        }
                    }
                }
                result.clear();
                result.addAll(add);
            }
        }
        return result;
    }

    public static void main(String[] args) {
        System.out.println(letterCombinations("2"));
    }
}
